package com.pasabahceambalaj.session;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

import com.pasabahceambalaj.entity.Firma;
import com.pasabahceambalaj.entity.Rol;

@Name("rolHome")
public class RolHome extends EntityHome<Rol> {

	@In(create = true)
	FirmaHome firmaHome;
	
	public void setRolId(Long id) {
		setId(id);
	}

	public Long getRolId() {
		return (Long) getId();
	}

	@Override
	protected Rol createInstance() {
		Rol rol = new Rol();
		return rol;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		
		Firma firma = null;
		if (Authenticator.isAdmin()) {
			firma = firmaHome.getDefinedInstance();
		} else {
			firma = Authenticator.getFirma();
		}

		if (firma != null) {
			getInstance().setFirma(firma);
		}
	}

	public boolean isWired() {
		if (getInstance().getFirma() == null)
			return false;
		return true;
	}

	public Rol getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

}
